<?php

namespace zhuli\web;

use zhuli\core\DiInterface;
use zhuli\web\Request;
use zhuli\web\Response;
use zhuli\web\View;
use ReflectionClass;

class Application
{
	private $request;
	private $response;
	private $view;
	private $di;
	private $controllerNamespace;

	/**
	 * __construct 构造方法
	 * @param Request  $request  请求
	 * @param Response $response 响应
	 * @param View     $view     视图
	 */
	public function __construct(Request $request, Response $response, View $view, DiInterface $di)
	{
		$this->request = $request;
		$this->response = $response;
		$this->view = $view;
		$this->di = $di;
	}

	/**
	 * setControllerNamespace 设置命名空间
	 * @param string $controllerNamespace 命名空间
	 */
	public function  setControllerNamespace($controllerNamespace)
	{
		$this->controllerNamespace = $controllerNamespace;
	}

	public function run()
	{
		$getControllerClass = $this->getControllerClass();//获取完全限定类名
		$reflect = new ReflectionClass($getControllerClass);//反射

		$instance = $reflect->newInstance();//创建新的实例

		print_r($instance);
		print_r($reflect->getMethods());//得到方法名
	}

	/**
	 * getControllerClass 获取完全限定类名
	 * @return string 完全限定类名
	 */
	public function getControllerClass()
	{
		$controllerId = $this->request->getControllerId();
		$controllerId = ucfirst($controllerId);//第一个字母大写

		return "{$this->controllerNamespace}\\{$controllerId}Controller";

	}
}